package com.example.ywj.toutiao.utils;

import android.graphics.Typeface;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.ywj.toutiao.R;
import com.example.ywj.toutiao.bean.Key;

import java.util.List;

public class GridView_BaseAdapter extends BaseAdapter {
    private static final String TAG = "GridView_BaseAdapter";
    private List<Key> list;
    public GridView_BaseAdapter(List<Key> list){
        this.list = list;
        //notifyDataSetChanged();
    }
    @Override
    public int getCount() {

        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder ;
        if(convertView == null){
            LayoutInflater inflater = LayoutInflater.from(parent.getContext());
            convertView = inflater.inflate(R.layout.item_key,null);
            viewHolder = new ViewHolder();
            viewHolder.tv = convertView.findViewById(R.id.item_key);
            viewHolder.tv2 = convertView.findViewById(R.id.item_key2);
            convertView.setTag(viewHolder);
        }else{
            viewHolder = (ViewHolder)convertView.getTag();
        }
        viewHolder.tv.setText(list.get(position).getKey());
        Typeface font = Typeface.createFromAsset(convertView.getContext().getAssets(), "iconfont.ttf");
        if(list.get(position).getLevel() == 0){
            viewHolder.tv2.setVisibility(View.INVISIBLE);
        }else if(list.get(position).getLevel() == 1){
            viewHolder.tv2.setTypeface(font);
            viewHolder.tv2.setTextColor(convertView.getContext().getResources().getColor(R.color.colorAccent));
            viewHolder.tv2.setText(convertView.getContext().getResources().getString(R.string.tuijian));
        }else if(list.get(position).getLevel() == 2){
            viewHolder.tv2.setTypeface(font);
            viewHolder.tv2.setTextColor(convertView.getContext().getResources().getColor(R.color.messageBlue));
            viewHolder.tv2.setText(convertView.getContext().getResources().getString(R.string.font8));
        }
        return convertView;
    }
    class ViewHolder{
        TextView tv;
        TextView tv2;
    }
}
